﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data;

using Gift.Model.crm;
using Gift.DAL.crm;
using Gift.Model.crm.eNum;

namespace WebSite.crm.order
{
    public partial class inlineOrderPrinter : BaseCrm
    {
        readonly t_DALOrder theOrder = new t_DALOrder();
        readonly t_DALOrderGoods theOrderGoods = new t_DALOrderGoods();
        readonly t_DALCompany theCompany = new t_DALCompany();
        t_Company oCompany;

        t_Company oStockCompany;
        t_Order oStockOrder;
        DataTable tbGoods;
        StringBuilder _sbGoodsList;

        public StringBuilder SbGoodsList
        {
            get { return _sbGoodsList; }
        }

        string _stockOrderCode;

        public string StockOrderCode
        {
            get { return _stockOrderCode; }
        }

        public string PrintDate
        {
            get { return DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"); }

        }
        string _supplyCompany;

        public string SupplyCompany
        {
            get { return _supplyCompany; }
        }

        string _linker;

        public string Linker
        {
            get { return _linker; }
        }
        string _linkerPhone;

        public string LinkerPhone
        {
            get { return _linkerPhone; }
        }
        string _goodsToDate;

        public string GoodsToDate
        {
            get { return _goodsToDate; }
        }

        decimal _sumOrderPrice;

        public string SumOrderPrice
        {
            get { return "¥" + _sumOrderPrice + "--元"; }
        }
        public string SumOrderPriceSupper
        {
            get { return Gift.Utile.MathLibrary.CmycurD(_sumOrderPrice); }
        }
        string _stockOrderRemark;

        public string StockOrderRemark
        {
            get { return _stockOrderRemark; }
        }
        string _stockCompany;

        public string StockCompany
        {
            get { return _stockCompany; }
        }
        string _stockCompanyAddress;

        public string StockCompanyAddress
        {
            get { return _stockCompanyAddress; }
        }


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.BuildForm();
            }
        }

        void BuildForm()
        {
            oStockOrder = theOrder.GetModel(int.Parse(Request.QueryString["id"]));
            this._stockOrderCode = oStockOrder.orderCode;
            this._goodsToDate = ((DateTime)oStockOrder.GoodsToDate).ToString("yyy年MM月dd日");
            this._linker = oStockOrder.linker;
            this._linkerPhone = oStockOrder.linkerPhone;
            this._stockOrderRemark = oStockOrder.remark;

            oCompany = theCompany.GetModel((int)oStockOrder.companyId);
            this._supplyCompany = oCompany.Name;

            oStockCompany = theCompany.GetModel((int)oStockOrder.orderCompanyId);

            this._stockCompany = oStockCompany.Name;
            this._stockCompanyAddress = oStockCompany.Provence + "," + oStockCompany.City + "," + oStockCompany.Address;

            tbGoods = theOrderGoods.GetGoodsListByOrderCode(oStockOrder.orderCode).Tables[0];

            _sbGoodsList = new StringBuilder();
            int i = 1;
            foreach (DataRow dr in tbGoods.Rows)
            {

                _sbGoodsList.AppendFormat("<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td><td>{5}</td><td>{6}</td></tr>"
                                       , i.ToString()
                                        , dr["brandName"].ToString()
                                        , dr["goodsName"].ToString()
                                        , dr["goodsPrice"].ToString()
                                         , dr["goodsCount"].ToString()
                                        , dr["costPrice"].ToString()
                                        , dr["sumOrderPrice"].ToString()
                                        );
                _sumOrderPrice = _sumOrderPrice + decimal.Parse(dr["sumOrderPrice"].ToString());
                i++;
            }


        }
    }
}